package com.huaxin.device.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huaxin.device.dto.ResponseResult;
import com.huaxin.device.dto.request.MetricCodeDictCreateReqDTO;
import com.huaxin.device.dto.request.MetricCodeDictPageListReqDTO;
import com.huaxin.device.dto.request.MetricCodeDictUpdateReqDTO;
import com.huaxin.device.models.MetricCodeDict;
import com.huaxin.device.service.MetricCodeDictService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "指标编码字典")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/device/metricCodeDict")
public class MetricCodeDictController {

    private final MetricCodeDictService service;

    @Operation(summary = "创建指标编码", description = "创建一个新的指标编码")
    @PostMapping("/create")
    public ResponseResult<MetricCodeDict> create(@RequestBody @Valid MetricCodeDictCreateReqDTO in) {
        return service.create(in);
    }

    @Operation(summary = "获取指标编码", description = "根据ID获取指标编码信息")
    @GetMapping("/get")
    public ResponseResult<MetricCodeDict> get(
            @Parameter(description = "主键ID", example = "1")
            @RequestParam(value = "id", required = true) Integer id) {
        MetricCodeDict entity = service.getByDictId(id);
        return ResponseResult.ok(entity);
    }

    @Operation(summary = "更新指标编码", description = "更新指标编码信息")
    @PostMapping("/update")
    public ResponseResult<String> update(@RequestBody @Valid MetricCodeDictUpdateReqDTO in) {
        return service.update(in);
    }

    @Operation(summary = "删除指标编码", description = "逻辑或物理删除指标编码")
    @DeleteMapping("/{id}/delete")
    public ResponseResult<String> delete(@PathVariable Integer id) {
        return service.delete(id);
    }

    @Operation(summary = "启用指标编码", description = "启用指标编码")
    @GetMapping("/active")
    public ResponseResult<String> active(
            @Parameter(description = "主键ID", example = "1")
            @RequestParam(value = "id", required = true) Integer id) {
        return service.active(id);
    }

    @Operation(summary = "禁用指标编码", description = "禁用指标编码")
    @GetMapping("/inactive")
    public ResponseResult<String> inactive(
            @Parameter(description = "主键ID", example = "1")
            @RequestParam(value = "id", required = true) Integer id) {
        return service.inactive(id);
    }

    @Operation(summary = "分页查询指标编码", description = "支持按条件分页查询指标编码")
    @PostMapping("/page")
    public ResponseResult<IPage<MetricCodeDict>> pageQuery(@RequestBody @Valid MetricCodeDictPageListReqDTO in) {
        return service.pageQuery(in);
    }
}